<?php

namespace app\common\model;

//use think\Model;

class TransferConfigModel extends BaseModel{

	protected $table = 'tp_transfer_config';

	/*
	提币列表
	 */
	public function transferList($uid){
		$data = $this->alias('e')
						->join('tp_coin_wallet w','w.id=e.wid and w.status=1')
						->join('tp_user_balance b','b.wid=e.wid and b.uid='.$uid,'LEFT')
						->join('tp_coin_wallet w2','w2.id=e.fee_wid and w2.status=1')
						->group('e.wid')
						->order('e.sort asc')
						->field('e.*,w.icon,w.name,b.balance,w2.name fee_name')
						->select();
		if(empty($data)){
			return [];
		}
		foreach ($data as $key => $val) {
			$data[$key]['balance'] = $data[$key]['balance']?:0;
			$data[$key]['balance'] = $data[$key]['balance']/1;
		}
		return  $data;
	}

	/*
	获取单个列表
	 */
	public function transOne($uid,$wid){
		$data = $this->alias('e')
						->join('tp_coin_wallet w','w.id=e.wid and w.status=1')
						->join('tp_user_balance b','b.wid=e.wid and b.uid='.$uid,'LEFT')
						->join('tp_coin_wallet w2','w2.id=e.fee_wid and w2.status=1')
						->where('e.wid',$wid)
						->field('e.*,w.icon,w.name,b.balance,w2.name fee_name')
						->find();
		if(empty($data)){
			return [];
		}
		$data['balance'] = $data['balance']?:0;
		$data['balance'] = $data['balance']/1;
		return  $data;
	}


	/*
	获取一条配置
	 */
	public function getOneConfig($id,$uid){
		$data = $this->alias('e')
						->join('tp_coin_wallet w','w.id=e.wid and w.status=1')
						->join('tp_user_balance b','b.wid=e.wid and b.uid='.$uid,'LEFT')
						->join('tp_coin_wallet w2','w2.id=e.fee_wid and w2.status=1')
						->where('e.id',$id)	
						->field('e.*,b.balance,w.name wallet_name,w2.name fee_name')
						->find();
		if ($data) {
			$data['balance'] = $data['balance']?:0;
		}
		return $data;
	}
}